﻿# Vanilla override
# character having its birthday in root scope
# tested after age has increased
on_birthday = {
	on_actions = {
		on_specific_birthday
		on_birthday_childhood
		on_birthday_adulthood
		on_graceful_aging_birthday
	}
}

on_specific_birthday = {
	first_valid_on_action = {
		on_3rd_birthday
		on_6th_birthday
		on_7th_birthday_ua
		on_10th_birthday_ua
		on_12th_14th_birthday_ua          # ← this is the early-adulthood hook
	}
}

# THIS IS THE MISSING BLOCK THAT FIXES EVERYTHING
on_12th_14th_birthday_ua = {
	trigger = {
		OR = {
			AND = { is_female = yes age = 12 }
			AND = { is_male   = yes age = 14 }
		}
	}
	# These two lines are the magic
	on_actions = {
		on_birthday_education_events_ua   # ← gives the actual education trait at 12/14
		on_birthday_adulthood             # ← converts childhood/personality traits + unlocks lifestyles
	}
}

on_birthday_childhood = {
	trigger = {
		OR = {
			is_adult = no
			is_ua_adult_preadult = yes
		}
		age >= childhood_education_start_age
	}
	on_actions = {
		on_birthday_education_events_ua
		on_action_add_sexuality
		reincarnation_toy_pulse
	}
	effect = {
		if = {
			limit = {
				any_parent = {
					is_playable_character = yes
					highest_held_title_tier >= tier_duchy
					any_memory = {
						memory_type = ascended_throne_memory
						has_variable = childhood_memory
						save_temporary_scope_as = throne_memory_temp
					}
				}
			}
			random_parent = {
				limit = {
					is_playable_character = yes
					highest_held_title_tier >= tier_duchy
					any_memory = {
						memory_type = ascended_throne_memory
						has_variable = childhood_memory
						save_temporary_scope_as = throne_memory_temp
					}
				}
				trigger_event = bp2_yearly.4003
			}
		}

		if = {
			limit = {
				culture = {
					has_cultural_parameter = strong_traits_more_common
				}
				NOR = {
					has_trait = strong
					has_trait = weak
					has_trait = physique_bad
				}
			}
			random = {
				chance = {
					value = 0
					if = {
						limit = { age >= 30 }
						add = 100
					}
				}
				add_trait = strong
			}
		}

		random = {
			chance = { value = 30 }
			tgp_learn_chinese_effect_birthday = yes
		}
	}
	random_events = {
		900 = 0
		150 = childhood.2100
		150 = childhood.2200
		150 = childhood.2300
	}
}

reincarnation_toy_pulse = {
	random_events = {
		chance_to_happen = 14
		100 = bp2_yearly.8090
	}
}

on_birthday_adulthood = {
	trigger = { is_adult = yes }
	random_events = {
		chance_to_happen = 25
		1000 = 0
		1 = bp1_yearly.3004
		30 = bp1_yearly.3006
	}
	effect = {
		if = {
			limit = {
				culture = { has_cultural_parameter = peasant_leader_is_inherited }
				any_parent ?= {
					even_if_dead = yes
					culture = root.culture
					has_trait = peasant_leader
				}
			}
			add_trait = peasant_leader
		}
	}
}

on_graceful_aging_birthday = {
	trigger = {
		dynasty ?= { has_dynasty_perk = kin_legacy_5 }
		age >= kin_legacy_5_start_age
		save_temporary_scope_value_as = {
			name = age_check
			value = kin_legacy_5_age_modulo
		}
		scope:age_check = 0
	}
	events = { dynasty_legacy.0001 }
}